CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

PROJECT(EyerWandArtist VERSION 1.0.0.0)

MESSAGE( STATUS "CMAKE_PROJECT_NAME    = ${CMAKE_PROJECT_NAME}" )
MESSAGE( STATUS "PROJECT_VERSION_MAJOR = ${PROJECT_VERSION_MAJOR}" )
MESSAGE( STATUS "PROJECT_VERSION_MINOR = ${PROJECT_VERSION_MINOR}" )
MESSAGE( STATUS "PROJECT_VERSION_PATCH = ${PROJECT_VERSION_PATCH}" )
MESSAGE( STATUS "PROJECT_VERSION_TWEAK = ${PROJECT_VERSION_TWEAK}" )
MESSAGE( STATUS "PROJECT_HOMEPAGE_URL = ${PROJECT_HOMEPAGE_URL}")
MESSAGE( STATUS "CMAKE_PROJECT_DESCRIPTION = ${CMAKE_PROJECT_DESCRIPTION}" )

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

MESSAGE(STATUS "operation system is ${CMAKE_SYSTEM}")

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")


SET(THIRD_PART_DIST_DIR "Lib")

IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    MESSAGE(STATUS "current platform: Linux ")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
    MESSAGE(STATUS "current platform: Windows")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Android")
    MESSAGE(STATUS "current platform: Android")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    MESSAGE(STATUS "current platform: Darwin")
    ADD_SUBDIRECTORY(EyerMetalTest)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "iOS")
    MESSAGE(STATUS "current platform: iOS")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Emscripten")
    MESSAGE(STATUS "current platform: Emscripten")
    SET(THIRD_PART_DIST_DIR "Lib_wasm")
ELSE ()
    MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}")
ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")

INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/QtLib/QtGui/)
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/QtLib/)

INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/EyerLib_install/include)
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/jsoncpp_install/include)
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/glfw_install/include)
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/freetype_install/include)
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/freetype_install/include/freetype2)

LINK_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/EyerLib_install/lib)
LINK_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/ffmpeg_install/lib)
LINK_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/x264_install/lib)
LINK_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/glfw_install/lib)
LINK_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/lame_install/lib)
LINK_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/jsoncpp_install/lib)
LINK_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/freetype_install/lib)
LINK_DIRECTORIES (${CMAKE_SOURCE_DIR}/../../${THIRD_PART_DIST_DIR}/libpng_install/lib)

SET(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install/)

OPTION(EWAUI_DEBUG     "option for EWAUI_DEBUG"     OFF)
IF (EWAUI_DEBUG)
    ADD_DEFINITIONS(-D EYER_EWAUI_DEBUG)
ENDIF(EWAUI_DEBUG)


OPTION(ENABLE_GCOV "Enable gcov (debug, Linux builds only)" OFF)
IF (ENABLE_GCOV AND NOT WIN32 AND NOT APPLE)
    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
    SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
    SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov")
ENDIF()

IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    MESSAGE(STATUS "current platform: Linux ")
    ADD_DEFINITIONS(-D EYER_PLATFORM_LINUX)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
    MESSAGE(STATUS "current platform: Windows")
    ADD_DEFINITIONS(-D EYER_PLATFORM_WINDOWS)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Android")
    MESSAGE(STATUS "current platform: Android")
    ADD_DEFINITIONS(-D EYER_PLATFORM_ANDROID)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    MESSAGE(STATUS "current platform: Darwin")
    ADD_DEFINITIONS(-D EYER_PLATFORM_DARWIN)
    set(CMAKE_EXE_LINKER_FLAGS
        "-framework IOKit -framework AudioToolbox -framework CoreGraphics -framework CoreMedia -framework Cocoa -framework VideoToolbox -framework AVFoundation -framework Security -framework CoreFoundation -framework CoreVideo -framework OpenGL -framework AppKit -framework CoreImage -framework VideoDecodeAcceleration"
    )
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Emscripten")
    MESSAGE(STATUS "current platform: Emscripten")
    ADD_DEFINITIONS(-D EYER_PLATFORM_EMSCRIPTEN)
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c++11 \
                                        -s WASM=1 \
                                        -s FULL_ES2=1 \
                                        -s FULL_ES3=1 \
                                        -s USE_WEBGL2=1 \
                                        -s USE_PTHREADS=1 \
                                        -s PTHREAD_POOL_SIZE=20 \
                                        -s WASM_MEM_MAX=1073741824 \
                                        -s TOTAL_MEMORY=1073741824 \
                                        -s INITIAL_MEMORY=67108864 \
                                        -s ALLOW_MEMORY_GROWTH=1 \
                                        -s FETCH=1 \
                                        -s EXPORTED_RUNTIME_METHODS=\"['ccall','stringToUTF8']\" \
                                        -s ASSERTIONS=1 -O3 -pthread \
                                        --js-library ${CMAKE_SOURCE_DIR}/library-ewa.js")

    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 \
                                        -s WASM=1 \
                                        -s FULL_ES2=1 \
                                        -s FULL_ES3=1 \
                                        -s USE_WEBGL2=1 \
                                        -s USE_PTHREADS=1 \
                                        -s PTHREAD_POOL_SIZE=20 \
                                        -s WASM_MEM_MAX=1073741824 \
                                        -s TOTAL_MEMORY=1073741824 \
                                        -s INITIAL_MEMORY=67108864 \
                                        -s ALLOW_MEMORY_GROWTH=1 \
                                        -s FETCH=1 \
                                        -s EXPORTED_RUNTIME_METHODS=\"['ccall','stringToUTF8']\" \
                                        -s ASSERTIONS=1 -O3 -pthread \
                                        --js-library ${CMAKE_SOURCE_DIR}/library-ewa.js")
ELSE ()
    MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}")
ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")

FUNCTION(ModuleTestOption moduleName moduleOption)
    IF (${moduleOption})
        ADD_SUBDIRECTORY(${moduleName})
    ENDIF(${moduleOption})
ENDFUNCTION(ModuleTestOption)

INCLUDE_DIRECTORIES (googletest/googletest/include)

SET(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install/)

ADD_SUBDIRECTORY(googletest)

ADD_SUBDIRECTORY(EWAUI)
ADD_SUBDIRECTORY(EWAUIWidget)
ADD_SUBDIRECTORY(EWAPrj)
ADD_SUBDIRECTORY(EWAUITimeline)

ADD_SUBDIRECTORY(EWAPrjTest)
ADD_SUBDIRECTORY(EWADesktopTest)

ADD_SUBDIRECTORY(EWAWebTest)

OPTION(UI_TEST     "option for UI_TEST"     ON)
IF (UI_TEST)
    ADD_SUBDIRECTORY(imgui)
    ADD_SUBDIRECTORY(EWAUIWidgetTest)
    ADD_SUBDIRECTORY(EWADesktop)
ENDIF(UI_TEST)

